<!--{template lyear:header_simple_start}-->
<link rel="stylesheet" href="static/lyear/js/layui/css/layui.css?{VERHASH}">
<style>
	.icon {
		width: 28px;
		height: 28px;
		margin-right: 5px;
	}
	.iconFirstWord {
		width: 18px;
		height: 18px;
		line-height: 16px;
		font-size: 12px;
	}
</style>
<!--{template lyear:header_simple_end}-->
<script type="text/javascript">
	var selorg={};
	selorg.add=function(ctrlid,vals){
		if(vals[0].orgid=='other') vals[0].path='{lang please_select_a_organization_or_department}';
		jQuery('#'+ctrlid+'_Menu').html(vals[0].path+' ');
		jQuery('#sel_'+ctrlid).val(vals[0].orgid);
	}
</script>
<main class="bs-main-container">
	<div class="container-fluid">
		<div class="card">
			<div class="card-body">
				<div class="btn-group" id="breadcrumb"><a href="javascript:;" class="btn btn-primary fid-btn">{lang all_typename_attach}</a></div>
			</div>
		</div>
		<div class="card">
			<div class="card-body">
				<div class="card-search mb-2-5">
					  <div class="row">
						<div class="col-md-4">
						  <div class="row">
							<label class="col-sm-4 col-form-label">名称</label>
							<div class="col-sm-8">
							  <input type="text" class="form-control pull-left" name="keyword" id="keyword" placeholder="{lang filemanage_file_user}">
							</div>
						  </div>
						</div>
						<div class="col-md-4">
						  <div class="row">
							<div class="dropdown org">
								<input id="sel_orgid_{$org['orgid']}" type="hidden" name="orgid"  value="$org['orgid']" onchange="selDepart(this)" />
								<button type="button" id="orgid_{$org['orgid']}_Menu" class="btn btn-primary dropdown-toggle" data-toggle="dropdown"> $org[depart]  </button>
								<div id="orgid_$orgid_dropdown_menu" class="dropdown-menu org-sel-box" role="menu" aria-labelledby="orgid_{$org['orgid']}_Menu">
								<iframe name="orgid_{$org['orgid']}_iframe" class="org-sel-box-iframe" src="index.php?mod=system&op=orgtree&template=1&ctrlid=orgid_{$org['orgid']}&nouser=1&stype=1&zero={eval echo urlencode('{lang unselect_a_organization_or_department}');}" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" allowtransparency="true" ></iframe>
								</div>
							</div>
						  </div>
						</div>
						<div class="col-md-4">
						  <button type="submit" class="btn btn-primary me-1" id="search-btn">搜索</button>
						  <button type="reset" class="btn btn-default" id="refreshsearch">重置</button>
						</div>
					  </div>
				  </div>
                <table class="layui-hide" id="table" lay-filter="table"></table>
				<script type="text/html" id="toolbar">
					<div class="layui-btn-container">
						<button type="button"  class="layui-btn layui-btn-normal layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
						<button type="button" class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delete">{lang delete}</button>
						<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="get">刷新</button>
					</div>
				</script>
				<script type="text/html" id="barDemo">
				<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">更多</a>
				<a class="layui-btn layui-btn--warm layui-btn-xs" lay-event="view">预览</a>
				<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="download">下载</a>
				<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
				</script>
			</div>
		</div>
	</div>
</main>
<script src="static/lyear/js/layui/layui.js?{VERHASH}"></script>
<script>
	var type = '';
	layui.use('table', function(){
	  var table = layui.table;
	  table.render({
		elem: '#table',
		url: '{MOD_URL}&do=getinfo',
		toolbar: '#toolbar',
		title: '文件管理数据表格',
		autoSort: false,
		even:true,
		cellMinWidth:120,
		text: {
			none: '暂无相关数据'
		},
		page: {
		  limit: 20,
		  limits: [10, 20, 50, 100, 200, 500, 1000,2000,5000]
		},
		cols: [[
		{type:'checkbox', fixed: 'left'}
		  ,{title: 'ID',width:80, fixed: 'left',type: 'numbers'}
		  <!--{if $_G['adminid']}-->,{field:'username', title: '{lang possessor}', sort: true, align: 'center',templet: function(d) {
          return d.username;
        }}<!--{/if}-->
		  ,{field:'name', title: '{lang filename}', sort: true,templet: function(d) {
          return d.name;
        }}
		  ,{field:'size', title: '{lang file_size}', align: 'center', sort: true}
		  ,{field:'type', title: '{lang file_type}', align: 'center', sort: true}
		  ,{field:'relpath', title: '{lang file_location}', align: 'left'}
		  ,{field:'dateline', title: '{lang add_time}', align: 'center', sort: true}
		  ,{field:'FileUri', title: '文件地址', hide:true}
		  ,{field:'md5', title: 'MD5', hide:true}
		  ,{field:'copys', title: '引用数', align: 'center',hide:true}
		  ,{field:'downloads', title: '{lang download_times}', align: 'center',hide:true}
		  ,{field:'views', title: '{lang view_count}', align: 'center',hide:true}
		  ,{field:'edits', title: '{lang edit_times}', align: 'center',hide:true}
		  ,{title: '{lang operation}',width:240, align:'center', toolbar: '#barDemo', fixed: 'right'}
		]],
		initSort: {
			field: 'dateline', // 默认排序字段
			type: 'desc' // 默认排序方式
		}
	  });
	  //头工具栏事件
	table.on('toolbar(table)', function(obj){
		var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
		var data = checkStatus.dataCache;
		switch(obj.event){
			case 'getCheckData':
				if (data.length === 0) {
					showmessage("请至少选择一行", 'danger', 3000, 1);
					return;
				}
				var template = '<div class="accordion">';
					data.forEach(function(item) {
						template += '<div class="accordion-item">';
						template += '<h2 class="accordion-header" id="Open-heading' + item.LAY_NUM + '">';
						template += '<button class="accordion-button" type="button" data-toggle="collapse" data-target="#Open-collapse' + item.LAY_NUM + '" aria-expanded="true" aria-controls="Open-collapse' + item.LAY_NUM + '">';
						template += '{lang filename}：' + item.name;
						template += '</button>';
						template += '</h2>';
						template += '<div id="Open-collapse' + item.LAY_NUM + '" class="accordion-collapse collapse show" aria-labelledby="Open-heading' + item.LAY_NUM + '">';
						template += '<div class="accordion-body">';
						template += '<p><strong>ID:</strong> ' + item.LAY_NUM + '</p>';
						<!--{if $_G['adminid']}-->
						template += '<p><strong>{lang possessor}:</strong> ' + item.username + '</p>';
						<!--{/if}-->
						template += '<p><strong>{lang file_size}:</strong> ' + item.size + '</p>';
						template += '<p><strong>{lang file_type}:</strong> ' + item.type + '</p>';
						template += '<p><strong>{lang file_location}:</strong> ' + item.relpath + '</p>';
						template += '<p><strong>{lang add_time}:</strong> ' + item.dateline + '</p>';
						<!--{if $_G['adminid']}-->
						if (item.FileUri) {
							template += '<p><strong>文件地址:</strong> ' + item.FileUri + '</p>';
						}
						if (item.copys) {
							template += '<p><strong>引用数:</strong> ' + item.copys + '</p>';
						}
						if (item.md5) {
							template += '<p><strong>MD5:</strong> ' + item.md5 + '</p>';
						}
						<!--{/if}-->
						if (item.isdelete !== undefined) {
							template += '<p><strong>是否在回收站:</strong> ' + item.isdelete + '</p>';
						}
						if (item.downs) {
							template += '<p><strong>{lang download_times}:</strong> ' + item.downs + '</p>';
						}
						if (item.views) {
							template += '<p><strong>{lang view_count}:</strong> ' + item.views + '</p>';
						}
						if (item.edits) {
							template += '<p><strong>{lang edit_times}:</strong> ' + item.edits + '</p>';
						}
						template += '</div>';
						template += '</div>';
						template += '</div>';
					});
				template += '</div>';
				layer.alert(template, {
					title: '选中的文件数据'
				});
				break;
				case 'delete':
					if (data.length === 0) {
						showmessage("请至少选择一行", 'danger', 3000, 1);
						return;
					}
					var postData = "";
					$.each(data,function(i) {
						postData +=  this.rid;
						if (i < data.length - 1) {
							postData += ",";
						}
					});
					layer.confirm('您确定要删除这'+data.length+'个文件(如果是文件夹将包含其下的子文件都会被删除)吗？删除之后不可恢复！', {skin:'lyear-skin-danger'}, function(index){
						var loading = layer.load(0, { shade:  [0.1, '#000'] });
						jQuery.post('{MOD_URL}&do=delete', {'icoid': postData},function(json){
							layer.close(loading);
							layer.close(index);
							if(json['msg']=='success'){
								showmessage('删除成功', 'success', '3000', 1);
								table.reloadData('table');
							}else if(json['msg']){
								showmessage(json['msg'], 'danger', '3000', 1);
							} else {
								showmessage('{lang error}', 'danger', '3000', 1);
							}
							},'json')
							.fail(function() {
								layer.close(loading);
								layer.close(index);
								showmessage('服务器发生错误，请稍后再试', 'danger',3000,1);
							});
					});
				break;
				case 'get':
				table.reloadData('table', {
					where: {type: type},
					page: {
						curr: 1
					}
				});
				break; 
			};
		});
	  //监听工具条
	  table.on('tool(table)', function(obj){
		var data = obj.dataCache;
		if(obj.event === 'detail'){
			showDataTemplate(obj);
		} else if(obj.event === 'view'){
			if (obj.data.ftype == 'folder') {
				// 刷新表格并传递搜索参数
				table.reloadData('table', {
					where: {pfid: obj.data.oid},
					page: {
						curr: 1
					},
					done: function(res, curr, count) {
						if(res.breadcrumb) {
							$('#breadcrumb').html(res.breadcrumb);
						}
					}
				});
			} else {
				var url = 'share.php?a=view&s='+obj.data.dpath;
				window.open(url);
			}
		} else if(obj.event === 'download'){
			var url = DZZSCRIPT + '?mod=io&op=download&path='+obj.data.dpath;
			window.open(url);
		} else if(obj.event === 'del'){
			layer.confirm('{lang filemanage_del_file}', {skin:'lyear-skin-danger'}, function(index){
				var loading = layer.load(0, { shade:  [0.1, '#000'] });
				$.ajax({
					type: "post",
					url: "{MOD_URL}&do=delete",
					data: {icoid: obj.data.rid},
					dataType: 'json',
					success: function (res, status) {
						layer.close(loading);
						layer.close(index);
						if (res.msg == 'success') {
							obj.del();
							showmessage('删除成功', 'success',3000,1);
						} else {
							showmessage(res.msg, 'danger',3000,1);
						}
					},
					error: function () {
						layer.close(index);
						layer.close(loading);
						showmessage('服务器发生错误，请稍后再试', 'danger',3000,1);
					}
				})
			});
		}
	  });
	  //触发排序事件 
	table.on('sort(table)', function(obj){
		table.reloadData('table', {
			initSort: obj
			,where: {
				field: obj.field
				,order: obj.type
			}
		});
	});
	  table.on('rowDouble(table)', function(obj){
		showDataTemplate(obj);
	  });
		function showDataTemplate(obj) {
			var data = obj.dataCache;
			var template =
			'<p><strong>ID:</strong> ' + data.LAY_NUM+ '</p>' +
			'<p><strong>{lang filename}:</strong> ' + data.name + '</p>' +
			<!--{if $_G['adminid']}-->
			'<p><strong>{lang possessor}:</strong> ' + data.username + '</p>' + 
			<!--{/if}-->
			'<p><strong>{lang file_size}:</strong> ' + data.size + '</p>' +
			'<p><strong>{lang file_type}:</strong> ' + data.type + '</p>' +
			'<p><strong>{lang file_location}:</strong> ' + data.relpath + '</p>' +
			'<p><strong>{lang add_time}:</strong> ' + data.dateline + '</p>' +
			<!--{if $_G['adminid']}-->
			(data.FileUri ? '<p><strong>文件地址:</strong> ' + data.FileUri + '</p>' : '') +
			(data.copys ? '<p><strong>引用数:</strong> ' + data.copys + '</p>' : '') +
			(data.md5 ? '<p><strong>MD5:</strong> ' + data.md5 + '</p>' : '') +
			<!--{/if}-->
			(data.isdelete !== undefined ? '<p><strong>是否在回收站:</strong> ' + data.isdelete + '</p>' : '') +
			(data.downs ? '<p><strong>{lang download_times}:</strong> ' + data.downs + '</p>' : '') +
			(data.views ? '<p><strong>{lang view_count}:</strong> ' + data.views + '</p>' : '') +
			(data.edits ? '<p><strong>{lang edit_times}:</strong> ' + data.edits + '</p>' : '');
	
			layer.alert(template, {
				title: data.name + ' 详情：'
			});
			// 标注选中样式
			obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
		}
		// 搜索按钮功能
		$(document).on('click', '#search-btn', function() {
		// 获取搜索关键词
		var keyword = $('#keyword').val();
		// 刷新表格并传递搜索参数
		table.reloadData('table', {
		  where: { keyword: keyword,orgid:$('#sel_orgid_{$org['orgid']}').val() },
		  page: {
			curr: 1 //重新从第 1 页开始
		  }
		});
	  });
	  var pfid = '';
		$(document).on('click', '.fid-btn', function() {
			table.reloadData('table', {
				where: {pfid:pfid}, // 清空搜索参数
				page: {
					curr: 1 //重新从第 1 页开始
				}
			});
		});
	   // 重置按钮功能
	   $('#refreshsearch').click(function() {
		// 清空表单内容
        $('#sel_orgid_{$org['orgid']}').val('');
        $('#keyword').val('');
		// 重置按钮内容
		$('#orgid_{$org['orgid']}_Menu').text('$org[depart]');
		// 刷新表格
		table.reloadData('table', {
		  where: {type: type}, // 清空搜索参数
		  page: {
			curr: 1 //重新从第 1 页开始
		  }
		});
	  });
	  // 类型按钮功能
	  $(document).on('click', '.type-btn', function() {
		// 移除所有 .type-btn 的 active 类
		$('.type-btn').removeClass('active');
		// 为当前点击的按钮添加 active 类
		$(this).addClass('active');
		// 获取当前的 type 值
		operation = $(this).data('operation');
		type = $(this).data('type');
		$('#keyword').val('');
		// 刷新表格并传递 operation 参数
		table.reloadData('table', {
		  where: {type: type},
		  page: {
			curr: 1 //重新从第 1 页开始
		  }
		});
	  });
	});
</script>
<!--{template lyear:footer_simple}-->